<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>易抽奖-新建抽奖2</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css" type="text/css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-3 visible-xs-*"></div>
        <div class="col-lg-6" style="background-color:#DCDCDC"><br>
            <div align="center">
                <p class="button3">新建抽奖</p>
            </div>
            <p class="font">奖项设定：</p>
            <p class="font2">说明：奖项可不填满</p>
            <p class="font2">中奖率不可填0和负数，确保中奖率之和小于等于一千</p><br>
            <div align="center">
                <table width="90%" border="0px">
                    <tr>
                        <th noWrap>奖项名称</th>
                        <th>奖品名称</th>
                        <th>数量(个）</th>
                        <th noWrap>中奖率(‰)</th>
                    </tr>
                    <tr>
                        <th>一等奖</th>
                        <th><input class="input" type="text" id="onename"/></th>
                        <th><input class="input" type="number" id="onenumber"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'/></th>
                        <th><input class="input" type="number" id="oneprobability"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                    </tr>
                    <tr>
                        <th>二等奖</th>
                        <th><input class="input" type="text" id="twoname"></th>
                        <th><input class="input" type="number" id="twonumber"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                        <th><input class="input" type="number" id="twoprobability"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>

                    </tr>
                    <tr>
                        <th>三等奖</th>
                        <th><input class="input" type="text" id="threename"></th>
                        <th><input class="input" type="number" id="threenumber"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                        <th><input class="input" type="number" id="threeprobability"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                    </tr>
                    <tr>
                        <th>四等奖</th>
                        <th><input class="input" type="text" id="fourname"></th>
                        <th><input class="input" type="number" id="fournumber"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                        <th><input class="input" type="number" id="fourprobability"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                    </tr>
                    <tr>
                        <th>五等奖</th>
                        <th><input class="input" type="text" id="fivename"></th>
                        <th><input class="input" type="number" id="fivenumber"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                        <th><input class="input" type="number" id="fiveprobability"
                                   onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))'></th>
                    </tr>
                </table>
            </div>
            <br><br><br><br>
            <div align="center">
                <button type="button" class="button2"/>
                提交</button><br><br><br><br></div>
        </div>
        <div class="col-lg-3 visible-xs-*"></div>

    </div>
</div>
</body>
<script>
    var passcode = 0;
    var creatorId = 0;
    var lotteryId = 0;
    var oneName = '', twoName = '', threeName = '', fourName = '', fiveName = '';
    var onePer = 0, twoPre = 0, threePre = 0, fourPre = 0, fivePre = 0;
    var oneNum = 0, twoNum = 0, threeNum = 0, fourNum = 0, fiveNum = 0;
    if (document.getElementById('onename').value == "")
    {
        oneName = 0, onePer = 0, oneNum = 0;
    }
    else {
        oneName=document.getElementById('onename').value;
        oneNum=document.getElementById('onenumber').value;
        onePer=document.getElementById('oneprobability').value;
    }
    if (document.getElementById('twoname').value == ""){
        twoName = 0, twoPre = 0, twoNum = 0;
    }
        else {
        twoName=document.getElementById('twoname').value;
        twoNum=document.getElementById('twonumber').value;
        twoPer=document.getElementById('twoprobability').value;
    }
    if (document.getElementById('threename').value == ""){
        threeName = 0, threePre = 0, threeNum = 0;
    }
        else{
        threeName=document.getElementById('threename').value;
        threeNum=document.getElementById('threenumber').value;
        threePer=document.getElementById('threeprobability').value;
    }
    if (document.getElementById('fourname').value == ""){
        fourName = 0, fourPre = 0, fourNum = 0;
    }
        else{
        fourName=document.getElementById('fourname').value;
        fourNum=document.getElementById('fournumber').value;
        fourPer=document.getElementById('fourprobability').value;
    }
    if (document.getElementById('fivename').value == ""){
        fiveName = 0, fivePre = 0, fiveNum = 0;}
        else {
        fiveName=document.getElementById('fivename').value;
        fiveNum=document.getElementById('fivenumber').value;
        fivePer=document.getElementById('fiveprobability').value;
    }
    $(document).ready(function () {
        function getUrlVal(para) {
            var search = location.search; //页面URL的查询部分字符串
            var arrPara = new Array(); //参数数组。数组单项为包含参数名和参数值的字符串，如“para=value”
            var arrVal = new Array(); //参数值数组。用于存储查找到的参数值

            if (search != "") {
                var index = 0;
                search = search.substr(1); //去除开头的“?”
                arrPara = search.split("&");

                for (i in arrPara) {
                    var paraPre = para + "="; //参数前缀。即参数名+“=”，如“para=”
                    if (arrPara[i].indexOf(paraPre) == 0 && paraPre.length < arrPara[i].length) {
                        arrVal[index] = decodeURI(arrPara[i].substr(paraPre.length)); //顺带URI解码避免出现乱码
                        index++;
                    }
                }
            }

            if (arrVal.length == 1) {
                return arrVal[0];
            } else if (arrVal.length == 0) {
                return null;
            } else {
                return arrVal;
            }
        }

        var url = window.location.search;
        passcode = getUrlVal("passcode");
        creatorId = getUrlVal("creatorId");
        lotteryId = getUrlVal("lotteryId");
    })

    $("button").click(function () {
        //传抽奖信息
        $.post("http://yb.upc.edu.cn:8084/lottery/createPrizes",
            {
                Authorization: localStorage.getItem("testtoken"),
                prizeName: "一等奖",
                prizeIntro: oneName,
                prizePercentage: onePer,
                prizeTotalNumber: oneNum,
                creatorId: creatorId,
                lotteryId: lotteryId
            },
            function (data) {
                window.open("newsuccess.html?code=" + passcode + "&lotteryId=" + lotteryId + "",'_self')
            }
        );
        $.post("http://yb.upc.edu.cn:8084/lottery/createPrizes",
            {
                Authorization: localStorage.getItem("testtoken"),
                prizeName: "二等奖",
                prizeIntro: twoName,
                prizePercentage: twoPre,
                prizeTotalNumber: twoNum,
                creatorId: creatorId,
                lotteryId: lotteryId
            },
            function (data) {

            }
        );
        $.post("http://yb.upc.edu.cn:8084/lottery/createPrizes",
            {
                Authorization: localStorage.getItem("testtoken"),
                prizeName: "三等奖",
                prizeIntro: threeName,
                prizePercentage: threePre,
                prizeTotalNumber: threeNum,
                creatorId: creatorId,
                lotteryId: lotteryId
            },
            function (data) {

            }
        );
        $.post("http://yb.upc.edu.cn:8084/lottery/createPrizes",
            {
                Authorization: localStorage.getItem("testtoken"),
                prizeName: "四等奖",
                prizeIntro: fourName,
                prizePercentage: fourPre,
                prizeTotalNumber: fourNum,
                creatorId: creatorId,
                lotteryId: lotteryId
            },
            function (data) {

            }
        );
        $.post("http://yb.upc.edu.cn:8084/lottery/createPrizes",
            {
                Authorization: localStorage.getItem("testtoken"),
                prizeName: "五等奖",
                prizeIntro: fiveName,
                prizePercentage: fivePre,
                prizeTotalNumber: fiveNum,
                creatorId: creatorId,
                lotteryId: lotteryId
            },
            function (data) {
            }
        );

    })
</script>
</body>
</html>